/**
 * 我的资料 - 编辑页面
 * @author shixc
 * @date 2018/02/27
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            form: '',
            rules: {
                ORG_NAME: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                NAME: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                SEX: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            }
        },
        callObj
    ;

    var PasswordEdit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'info',
                _lazy_ms: 1000,
            }, win);
        },
        update: function () {
            app.ajax({
                xurl: 'updateMyInfo',
                xdata: vueData.form,
                loading: true,
                okmsg: '我的资料修改成功',
                cb: function (result) {
                    if (result.ok) {
                        layer.close(layer.index);
                    }
                }
            });
        },
        _call: function (obj) {


        },
        _ready: function () {

            vueData.form = app.fields_(['sys_user']);
            new Vue({
                el: '#info',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layer.index);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                self.update();
                            }
                        });
                    }
                },
                created: function () {
                    self._setEleIsReady('info');
                }
            });
        },
        _lazy: function () {
            this._super();
            app.ajax({
                xurl: 'sys/user/getUser',
                cb: function (result) {
                    if(result.ok){
                        var data = result.data.data;
                        app.extendUpLow({
                            target: vueData.form,
                            res: data,
                            reset: true
                        });

                        app.lStorage.set('_UserName', data.NAME,'2d');
                    }
                }
            });
        }
    });

    return new PasswordEdit();

});